<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2014 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Tuolaji <479923197@qq.com>
// +----------------------------------------------------------------------
namespace Api\Controller;

use Common\Controller\AppframeController;

header('Content-Type: text/plain; charset=utf-8');
class GerenController extends AppframeController {

	  //显示文字
	function za(){
		$id = I("id");
		if(!$id){
			exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		}
		 $data = M("za")->where("id = $id")->find();
		exit(json_encode(array('status'=>'200','data'=>$data)));
	}

	//所有标签
	function all_lable_lst(){

		$data1 = M("geren_lable")->where("is_del=0 and type = 1")->select();
		$data2 = M("geren_lable")->where("is_del=0 and type = 2")->select();
		$data3 = M("geren_lable")->where("is_del=0 and type = 3")->select();
		$data4 = M("geren_lable")->where("is_del=0 and type = 4")->select();
		$data5 = M("geren_lable")->where("is_del=0 and type = 5")->select();
		$data6 = M("geren_lable")->where("is_del=0 and type = 6")->select();
		$data7 = M("geren_lable")->where("is_del=0 and type = 7")->select();

		$data8 = M("tonggao_lable")->where("is_del=0 and type = 1")->select();
		$data9 = M("tonggao_lable")->where("is_del=0 and type = 2")->select();
		$data10 = M("tonggao_lable")->where("is_del=0 and type = 3")->select();
		$data11 = M("tonggao_lable")->where("is_del=0 and type = 4")->select();

		$data12 = M("cover_lable")->where("is_del=0")->select();
		exit(json_encode(array('status'=>'200','data'=>array(array('key'=>'职业属性','name'=>$data1,'leixing'=>'1'),array('key'=>"类型",'name'=>$data2,'leixing'=>'1'),array('key'=>"特长",'name'=>$data3,'leixing'=>'1'),array('key'=>'风格','name'=>$data4,'leixing'=>'1'),array('key'=>'外貌','name'=>$data5,'leixing'=>'1'),array('key'=>'体型','name'=>$data6,'leixing'=>'1'),array('key'=>'魅力部位','name'=>$data7,'leixing'=>'1'),array('key'=>'影视表演','name'=>$data8,'leixing'=>'2'),array('key'=>'平面拍摄','name'=>$data9,'leixing'=>'2'),array('key'=>'会展活动','name'=>$data10,'leixing'=>'2'),array('key'=>'网络宣传','name'=>$data11,'leixing'=>'2'),array('key'=>'自荐标签','name'=>$data12,'leixing'=>'3')))));
	}


	//获取用户的所有的信息
	 function full_details(){
		 $uid = I("uid");
//		 $uid = 1;
		 if($uid){
			 $data = M("account")->where("id = '{$uid}'")->find();
			 exit(json_encode(array('status'=>'200','data'=>$data)));
		 }else{
			 exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		 }
	 }

//	//省份
	function sheng(){

		$data1 = M("hot_city")->where("is_del=0")->field("id,name")->select();
		$data2 = M("region")->where("level='1' and zimu='a'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data3 = M("region")->where("level='1' and zimu='b'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data4 = M("region")->where("level='1' and zimu='c'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data5 = M("region")->where("level='1' and zimu='f'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data6 = M("region")->where("level='1' and zimu='g'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data7 = M("region")->where("level='1' and zimu='h'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data8 = M("region")->where("level='1' and zimu='j'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data9 = M("region")->where("level='1' and zimu='l'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data10 = M("region")->where("level='1' and zimu='n'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data11 = M("region")->where("level='1' and zimu='q'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data12 = M("region")->where("level='1' and zimu='s'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data13 = M("region")->where("level='1' and zimu='t'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data14 = M("region")->where("level='1' and zimu='x'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data15 = M("region")->where("level='1' and zimu='y'")->order("pinyin asc")->field("id,name,pinyin") ->select();
		$data16 = M("region")->where("level='1' and zimu='z'")->order("pinyin asc")->field("id,name,pinyin") ->select();

		exit(json_encode(array('status'=>'200','data'=>array(array('key'=>'热门','name'=>$data1),array('key'=>"A",'name'=>$data2),array('key'=>"B",'name'=>$data3),array('key'=>'C','name'=>$data4),array('key'=>'F','name'=>$data5),array('key'=>'G','name'=>$data6),array('key'=>'H','name'=>$data7),array('key'=>'J','name'=>$data8),array('key'=>'L','name'=>$data9),array('key'=>'N','name'=>$data10),array('key'=>'Q','name'=>$data11),array('key'=>'S','name'=>$data12),array('key'=>'T','name'=>$data13),array('key'=>'X','name'=>$data14),array('key'=>'Y','name'=>$data15),array('key'=>'Z','name'=>$data16)))));
	}


	//用户的基本信息 添加
	function personal(){
			$uid = I("uid");
		     $head_img =  trim(I("head_img"));
		     $nickname = trim(I("nickname"));
		     $birthday =  trim(I("birthday"));
		     $sex = trim(I("sex"));
			$school =  trim(I("school"));
			$is_qianyue =  trim(I("is_qianyue"));
			$address =  trim(I("address"));
			$height =  trim(I("height"));
			$weight =  trim(I("weight"));
			$bust =  trim(I("bust"));
			$yaowei =  trim(I("yaowei"));
			$hipline =  trim(I("hipline"));
			$shoe_size =  trim(I("shoe_size"));
		    $zhiye_lable = I("zhiye_lable");


		    $type_lable =  trim(I("type_lable"));
			$techang_lable =  trim(I("techang_lable"));
			$style_lable =  trim(I("style_lable"));
			$appearance_lable =  trim(I("appearance_lable"));
			$shape_lable =  trim(I("shape_lable"));
			$glamour_lable =  trim(I("glamour_lable"));



			if($head_img){
				$data['head_img'] = $head_img;
			}else{}
			if($nickname){
				$data['nickname'] = $nickname;
			}else{}
		    if($birthday){
			   $data['birthday'] = $birthday;
				$data['old'] = time()- $birthday;
		   }else{}
			if($sex){
				$data['sex'] = $sex;     // 0男  1女  2保密
			}else{}
			if($school){
				$data['school'] = $school;
			}else{}
			if($is_qianyue){
				$data['is_qianyue'] = $is_qianyue;       //(1/2)     0未签约  1已签约
			}else{}
			if($address){
				$data['address'] = $address;
			}else{}
			if($height){
				$data['height'] = $height;
			}else{}
			if($weight){
				$data['weight'] = $weight;
			}else{}
			if($bust){
				$data['bust'] = $bust;
			}else{}
			if($yaowei){
				$data['yaowei'] = $yaowei;
			}else{}
			if($hipline){
				$data['hipline'] = $hipline;
			}else{}
			if($shoe_size){
				$data['shoe_size'] = $shoe_size;
			}else{}
			if($zhiye_lable){
				$data['zhiye_lable'] = $zhiye_lable;
			}else{}
			if($type_lable){
				//类型标签
				$data['leixing_lable'] = $type_lable;
			}else{}
			if($techang_lable){
				//特长标签
				$data['techang_lable'] = $techang_lable;
			}else{}
			if($style_lable){
				//风格标签
				$data['fengge_lable'] = $style_lable;
			}else{}
			if($appearance_lable){
				//外貌标签
				$data['waimao_lable'] = $appearance_lable;
			}else{}
			if($shape_lable){
				//体型标签
				$data['tixing_lable'] = $shape_lable;
			}else{}
			if($glamour_lable){
				//魅力部位标签
				$data['meilibuwei_lable'] = $glamour_lable;
			}else{}
		    $data['is_huiyuan'] = 0;
		    $data['is_renzheng'] = 0;
		//职业属性标签

		$zhiye_lables = explode(",",$zhiye_lable);

		$data["zhiye_lable_id"]  =  $zhiye_lables[0];
			M("account")->where("id = '{$uid}'")->save($data);
		   $dd = M("account")->where("id = '{$uid}'")->find();

		    exit(json_encode(array('status'=>'200','data'=>$dd)));

		}



	//推荐信息
	function recommend(){
		$uid = trim(I("uid"));
		if($uid){
			$dat = M("account ac")
				->join(" left join " . C("DB_PREFIX") . "geren_lable gl on ac.zhiye_lable_id = gl.id")
				->where("ac.id = $uid")
				->field("ac.head_img,ac.nickname,gl.lable,ac.zhiye_lable_id,ac.images")
				->find();
		} else{
			exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		}

		if($dat['images']==""){
			exit(json_encode(array('status'=>'201','data'=>"请先在相册中选择图片")));
		}else{
			exit(json_encode(array('status'=>'200','data'=>$dat)));
		}
	}
	//推荐信息 修改保存
	function recommend_sav(){
		$uid = trim(I("uid"));
		$images= I("images");
//		$uid = 1;
		if(!$uid){
			exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		}else{
			$dat['images'] =  $images;
			M("account")->where("id = $uid")->save($dat);
			$aa = M("account")->where("id = $uid")->find();
			exit(json_encode(array('status'=>'200','data'=>$aa)));
		}

	}


	//通告信息 列表
	function tonggao_information(){
		$uid = trim(I("uid"));    //用户的id
//		$uid = 1;
		if($uid){
			$data = M("tonggao t")
				->join(" left join " . C("DB_PREFIX") . "account a on t.account_id = a.id")
				->join(" left join " . C("DB_PREFIX") . "tonggao_lable tl on t.tonggao_biaoqian = tl.id")
				->where("t.account_id = '{$uid}' and t.is_del = 0")
				->field("t.*,a.nickname,a.head_img,a.height,tl.lable")
			     ->select();
		}

		if($data){
			exit(json_encode(array('status'=>'200','data'=>$data)));
		}else{
			exit(json_encode(array('status'=>'201','data'=>'您还未发过通告')));
		}

	}
	//通告信息 编辑 点击保存
	function tonggao_information_sav(){
			$id = I("id");         //通告的id
			if(!$id){
				exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
			}
		     $stime =  I("stime");    //通告的开始时间
		     if($stime){
				 $dat['stime'] =  $stime;
			 }else{}
		$etime=  I("etime");    //通告的结束时间
		if($etime){
			$dat['etime'] = $etime;    //通告的结束时间
		}else{}
		$name =  I("name");        //通告名称
		if($name){
			$dat['name'] =  $name;
		}else{}
		$baochou =  I("baochou");       //报酬
		if($baochou){
			$dat['baochou'] =  $baochou;
		}else{}
		$address =  I("address");
		if($address){
			$dat['address'] = $address;
		}else{}
		$renshu=  I("renshu");
		if($renshu){
			$dat['renshu'] = $renshu;      //人数
		}else{}
		$tonggao_biaoqian =  I("tonggao_biaoqian");    //通告的标签 是一个
		if($tonggao_biaoqian){
			$dat['tonggao_biaoqian'] = $tonggao_biaoqian;
		}else{}

		$sex= trim(I("sex"));   //  （0/1/2）   0男  1女  2不限
		if($sex){
			$dat['sex'] =  $sex;
		}else{}
		$contacts= I("contacts");   //
		if($contacts){
			$dat['contacts'] = $contacts;   //联系人
		}else{}
		$phone= I("phone");   //
		if($phone){
			$dat['phone'] = $phone;    //联系人电话
		}else{}
		$details= I("details");   //
		if($details){
			$dat['details'] = $details;   //工作详情
		}else{}
		$height_s= I("height_s");   //
		if($height_s){
			$dat['height_s'] = $height_s;    //身高的开始
		}else{}
		$height_e= I("height_e");   //
		if($height_e){
			$dat['height_e'] = $height_e;   //身高的结束
		}else{}
		M("tonggao")->where("id=$id")->save($dat);

			$tonggao = M("tonggao")->where("id=$id")->find();

			if($tonggao){
				exit(json_encode(array('status'=>'200','data'=>$tonggao)));
			}else{
				exit(json_encode(array('status'=>'201','data'=>'保存失败')));
			}
	}
	//通告信息 列表页 删除
	function tonggao_del(){
		$id = I("id");  //通告表的id
//		$id = 1;
		if(!$id){
			exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		}
		$data = M("tonggao")->where("id = '{$id}'")->find();

		if($data){
			$dd['is_del']=1;
			M("tonggao")->where("id = $id")->save($dd);
			exit(json_encode(array('status'=>'200','data'=>"删除通告成功")));
		}else{
			exit(json_encode(array('status'=>'201','data'=>'没有通告信息')));
		}
	}




	//我的相册  保存
	function my_album_sav(){
		$uid = I("uid");  //用户的ID
//		$uid = 1;
		if(!$uid){
			exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		}
		$album = I("images");     //接收过来是字符串
//		 $album = "https://q.qlogo.cn/qqapp/1106568601/760CA2A58C135474E9A02EEC47A161FF/100,https://q.qlogo.cn/qqapp/1106568601/760CA2A58C135474E9A02EEC47A161FF/100,https://q.qlogo.cn/qqapp/1106568601/760CA2A58C135474E9A02EEC47A161FF/100";
		$xiangce = explode(",",$album);
		  $im =  M("account")->where("id = $uid")->find();
		 if(!$im['images']){
			 $dat['images'] = $xiangce[0]; //往推荐照片保存默认第一张图片
		 }else{}

		 $dat['album'] =  $album;

		 M("account")->where("id = $uid")->save($dat);
		$data = M("account")->where("id = $uid")->find();

		exit(json_encode(array('status'=>'200','data'=>$data)));


	}

	//把相册里的某张照片设置成推荐  保存
	function my_album_tuijian(){
		$uid = I("uid");  //用户的ID
//		$uid = 1;
		$album = I("images");
//		$album = 'https://q.qlogo.cn/qqapp/1106568601/760CA2A58C135474E9A02EEC47A161FF/100';

		if(!$uid){
			exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		}
		$dat['images'] =  $album;
		M("account")->where("id = $uid")->save($dat);
		$data = M("account")->where("id = $uid")->find();
		if($data['images']){
			exit(json_encode(array('status'=>'200','data'=>$data)));
		}else{
			exit(json_encode(array('status'=>'201','data'=>'上传的图片不能为空')));
		}
	}


	//我的自荐 列表页
	function my_cover(){
		$page = I("page");
		if(empty($page)){
			$page = 1;
		}
		$uid = I("uid");  //用户的ID
		if(!$uid){
			exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		}

		$count =  M("cover co")
			->join(C("DB_PREFIX") . "account ac on co.account_id = ac.id")
			->join(C("DB_PREFIX") . "cover_lable cl on co.cover_lable_id = cl.id")
			->where("co.account_id = $uid and co.is_del = 0")
			->count();
		$totalpage = ceil($count/10);
//		array('数据'=>$data,'totalpage'=>$totalpage)


		$data = M("cover co")
			->join(C("DB_PREFIX") . "account ac on co.account_id = ac.id")
			 ->join(C("DB_PREFIX") . "cover_lable cl on co.cover_lable_id = cl.id")
			->where("co.account_id = $uid and co.is_del = 0")
			->field("co.*,ac.id,ac.head_img,ac.nickname,cl.id,cl.lable")
			->limit(($page-1)*10,10)
			->select();
		if($data) {
			exit(json_encode(array('status'=>'200','data'=>array('data'=>$data,'totalpage'=>$totalpage))));
		}else{
			exit(json_encode(array('status'=>'201','data'=>'没有自荐信息')));
		}
	}

	//我的自荐 列表页 删除
	function my_cover_del(){
		$id = I("id");  //自荐表的id
//		$id = 1;
		if(!$id){
			exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		}
		$data = M("cover")->where("id = '{$id}'")->find();

		if($data){
			      $dd['is_del']=1;
			      M("cover")->where("id = $id")->save($dd);
			exit(json_encode(array('status'=>'200','data'=>"删除自荐成功")));
		}else{
			exit(json_encode(array('status'=>'201','data'=>'没有自荐信息')));
		}
	}


	//我的视频  保存
	function my_video_sav(){
		$uid = I("uid");  //用户的ID
//		$uid = 1;
		$video = I("video");
//		$video = "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq";
		if(!$uid){
			exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		}
		$dat['video'] =  $video;

		M("account")->where("id = $uid")->save($dat);
		$data = M("account")->where("id = $uid")->find();
		if($data['video']){
			exit(json_encode(array('status'=>'200','data'=>$data)));
		}else{
			exit(json_encode(array('status'=>'201','data'=>'没有视频')));
		}

	}

	 //认证 信息提交
	function shiming_renzheng_sav(){
		$uid = I("uid");
//		$uid = 1;
		$name = trim(I("name"));
//		$name = "赵小杰";
		$shenfenzheng = trim(I("shenfenzheng_num"));
//		$shenfenzheng = '130432198806040318';
		$shenfenzheng_photo = trim(I("shenfenzheng_img"));
//		$shenfenzheng_photo = "123456";
		if(!$uid || !$name || !$shenfenzheng_photo){
			exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		}
		$account = M("account")->where("id = $uid")->find();
		if($account){
			$dat['name'] = $name;
			$dat['shenfenzheng'] = $shenfenzheng;
			$dat['shenfenzheng_photo'] = $shenfenzheng_photo;
			$dat['is_renzheng'] = 1;
			$dat['renzheng_times'] = time();
			M("account")->where("id = $uid")->save($dat);

			exit(json_encode(array('status'=>'200','data'=>"认证成功")));
		}else{
			exit(json_encode(array('status'=>'201','data'=>'认证失败')));
		}
	}

	//意见反馈 提交
	function yijian_fankui_sav(){
		$uid = I("uid");
//		$uid = 1;
		$content = trim(I("content"));
//		 $content = "1111111111122222222222222333333333333";
		if(!$uid || !$content ){
			exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		}
		 $account = M("account")->where("id = $uid")->find();
		 if($account){
			 $dat['account_id'] = $uid;
			 $dat['content'] = $content;
			 $dat['ctime'] = time();
			 M("opinion")->add($dat);
			 exit(json_encode(array('status'=>'200','data'=>"成功")));
		 }else{
			 exit(json_encode(array('status'=>'201','data'=>"该用户未注册")));
		 }
	}

	//通告和推荐 点击的刷新
	function shuaxin(){
		$uid = I("uid");      // 推荐id(用户的id)   和  通告id  两个 每次调用至少传一个id

		if(!$uid){
			exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		}
		$tonggao_id = I("tonggao_id");

			$data = M("account")->where("id = $uid")->field("id,shuaxin_num,is_member,is_jia_shaxin")->find();
			if($data['is_member'] == 1){
				if($data['shuaxin_num']>2 && $data['is_jia_shaxin']==0){
					exit(json_encode(array('status'=>'201','data'=>'会员每天只可免费刷新三次,如果您想继续刷新，请付费刷新')));
					//会员每天免费刷新三次 超过三次点击按钮 购买一次刷新
				  }elseif($data['shuaxin_num']>2 && $data['is_jia_shaxin']!=0){
					if($uid){
						if($uid==1){
							//应付苹果审核
						}else{
							$data['shuaxin_num'] += 1;
						}
						$data['shuaxin_times'] = time();
						M("account")->where("id = $uid")->save($data);
					}elseif($tonggao_id){
						$dat['shuaxin_times'] = time();
						M("tonggao")->where("id = {$tonggao_id}")->save($dat);
					}
					$aa['is_jia_shaxin']=0;
					M("account")->where("id = $uid")->save($aa);
					exit(json_encode(array('status'=>'200','data'=>"刷新成功")));
				}else{
					if($uid){
						if($uid==1){
							   //应付苹果审核
						}else{
							$data['shuaxin_num'] += 1;
						}
						$data['shuaxin_times'] = time();
						M("account")->where("id = $uid")->save($data);
					}elseif($tonggao_id){
						$dat['shuaxin_times'] = time();
						M("tonggao")->where("id = {$tonggao_id}")->save($dat);
					}
					exit(json_encode(array('status'=>'200','data'=>"刷新成功")));
				}
			}else{
				 if($data[is_jia_shaxin]==0){
					 exit(json_encode(array('status'=>'202','data'=>"您还不是会员，请付费刷新")));
				 }else{
					 if($uid){
						 if($uid==1){
							 //应付苹果审核
						 }else{
							 $data['shuaxin_num'] += 1;
						 }
						 $data['shuaxin_times'] = time();
						 M("account")->where("id = $uid")->save($data);
					 }elseif($tonggao_id){
						 $dat['shuaxin_times'] = time();
						 M("tonggao")->where("id = {$tonggao_id}")->save($dat);
					 }
					 $aa['is_jia_shaxin']=0;
					 M("account")->where("id = $uid")->save($aa);
					 exit(json_encode(array('status'=>'200','data'=>"刷新成功")));
				 }

			}

	}

	 function tonggao_xiangqing(){
		 $tonggao_id  = I("tonggao_id");
		 if(!$tonggao_id){
			 exit(json_encode(array('status'=>'10003','data'=>'缺少参数')));
		 }
		 $data = M("tonggao")->where("id = {$tonggao_id}")->select();
		  if($data){
			  exit(json_encode(array('status'=>'200','data'=>$data)));
		  }
	 }

























}